<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\ExcelExport\TeamExpoter;
use App\Admin\Extensions\Tools\ImportButton;
use App\Models\Team;

use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;

class TeamController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('团队');
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('编辑');
            $content->body($this->form()->edit($id));
        });
    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Team::class, function (Grid $grid) {
            $grid->actions(function ($actions) {
                $actions->disableView();
            });
            $grid->disableCreateButton();
            $grid->filter(function($filter){
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                // 在这里添加字段过滤器
                $filter->like('team_id', '团队编号');
                $filter->like('guide', '导游');
                $filter->like('travel_agency', '旅行社');
                $filter->like('transport_company', '运输公司');
                $filter->equal('arrive_date', '抵达时间')->date();
            });
            $grid->tools(function ($tools) {
                $tools->append(new ImportButton('teams'));
            });
            $grid->exporter(new TeamExpoter());
            $grid->id('ID');
            $grid->name('姓名');
            $grid->sex('性别');
            $grid->card_type('身份证');
            $grid->id_card('证件号');
            $grid->birthday('出生日期');
            $grid->team_id('团队编号');
            $grid->origin('客源地');
            $grid->destination('目的地');
            $grid->guide('导游');
            $grid->guide_phone('导游电话');
            $grid->travel_agency('所属旅行社');
            $grid->hotel('入住酒店');
            $grid->transport_company('客运公司');
            $grid->car_id('车牌号');
            $grid->driver('司机');
            $grid->arrive_date('抵达日期')->sortable();
            $grid->leave_date('离开日期')->sortable();

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Team::class, function (Form $form) {

            $form->display('id', 'ID');
        });
    }
}
